package com.kurumi.thread;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.kurumi.constant.HomepageConstatnt;
import com.kurumi.domain.ShandongHomepageExcelDTO;
import com.kurumi.pojo.homepage.HomepagePdf;
import com.kurumi.pojo.homepage.MedicalRecordTurn;
import com.kurumi.service.MedicalRecordDataManageService;
import com.kurumi.util.DateUtil;
import com.kurumi.util.ObjectUtils;
import com.kurumi.util.ReflectHelper;
import com.kurumi.util.StringUtil;

/**
 * 首页数据处理多线程
 * 
 * @author liyutao
 *
 */
public class GenerateHomePagePDFCallable implements Callable<Integer> {

	private static final Logger logger = LoggerFactory.getLogger(GenerateHomePagePDFCallable.class);

	/**
	 * 分批guid集合
	 */
	private List<String> guidList;

	private MedicalRecordDataManageService medicalRecordDataManageService;
	
	private String homepagePdfTemplate;
	
	private String homepagePdfBasepath;

	public GenerateHomePagePDFCallable() {

	}

	public GenerateHomePagePDFCallable(List<String> guidList,
			MedicalRecordDataManageService medicalRecordDataManageService,
			String homepagePdfTemplate,
			String homepagePdfBasepath) {
		this.guidList = guidList;
		this.medicalRecordDataManageService = medicalRecordDataManageService;
		this.homepagePdfTemplate = homepagePdfTemplate;
		this.homepagePdfBasepath = homepagePdfBasepath;
	}
	
	

	public String getHomepagePdfTemplate() {
		return homepagePdfTemplate;
	}

	public void setHomepagePdfTemplate(String homepagePdfTemplate) {
		this.homepagePdfTemplate = homepagePdfTemplate;
	}

	public String getHomepagePdfBasepath() {
		return homepagePdfBasepath;
	}

	public void setHomepagePdfBasepath(String homepagePdfBasepath) {
		this.homepagePdfBasepath = homepagePdfBasepath;
	}

	@Override
	public Integer call() throws Exception {
		ShandongHomepageExcelDTO homepageData = null;
		for (String guid : guidList) {
			// 查询病案json
			Map<String, Object> jsonMap = medicalRecordDataManageService.getMedicalRecordMapByGuid(guid);
			logger.info("线程：{}，正在处理guid为:{}的数据", Thread.currentThread().getName(), guid);
			homepageData = new ShandongHomepageExcelDTO();
			// 初始化常量信息
			// initHomepageData(homepageData);
			// 初始化基本信息
			String onlyId = handleHomepageBaiscData(jsonMap, homepageData);
			
			if(StringUtils.isEmpty(onlyId)) {
				logger.error("唯一标识为空!");
				continue;
			}
			// 处理治疗信息
			handleCureInfoData(jsonMap, homepageData);
			// 处理诊断信息
			handleDiagInfo(jsonMap, homepageData);
			// 处理护理记录
			handleNurseInfo(jsonMap, homepageData);

			// 处理手术信息
			hadleOperationInfo(jsonMap, homepageData);
			// 处理费用信息
			hadleCostInfo(jsonMap, homepageData);
			// 处理转科数据
			handleTransferDeptInfo(jsonMap, homepageData);
			// 生成pdf
			generateHomePageByPdf(homepageData, guid,onlyId);

			// homepageHandleDataList.add(homepageData);

		}
		return guidList.size();
	}

	/**
	 * 生成首页PDF
	 * @param homepageData
	 * @param guid
	 */
	private void generateHomePageByPdf(ShandongHomepageExcelDTO homepageData, String guid,String onlyId) throws Exception{
		PdfReader reader = null;
		OutputStream bos = null;
		PdfStamper stamper = null;
		try {
			
			// pdf生成路径
			String pdfpath = StringUtil.getPdfPath(homepageData.getBAH())+homepageData.getBAH()+"/";
			
			File pdfFile = new File(homepagePdfBasepath+pdfpath);
			if(!pdfFile.exists()) {
				pdfFile.mkdirs();
			}
			String pdfName = onlyId+".pdf";
			HomepagePdf homepagePdf = new HomepagePdf();
			homepagePdf.setCreateTime(new Date());
			homepagePdf.setMrId(homepageData.getBAH());
			homepagePdf.setOnlyId(onlyId);
			homepagePdf.setVisitGuid(guid);
			homepagePdf.setFilePath(pdfpath);
			homepagePdf.setStatus("0");
			homepagePdf.setFileName(pdfName);
			reader = new PdfReader(homepagePdfTemplate);// 读取pdf模板
			bos = new FileOutputStream(new File(homepagePdfBasepath+pdfpath+pdfName));
			stamper = new PdfStamper(reader, bos);
			AcroFields form = stamper.getAcroFields();
			// 使用中文字体
			BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			ArrayList<BaseFont> fontList = new ArrayList<BaseFont>();
			fontList.add(bf);
			form.setSubstitutionFonts(fontList);
			
			// 利用反射将数据动态渲染
			String [] filedNames = ReflectHelper.getFiledName(homepageData);
			for (String fieldName : filedNames) {
				form.setField(fieldName,ReflectHelper.getFieldValueByName(fieldName, homepageData));
			}
			// 根据唯一标识查询首页pdf信息
			
			HomepagePdf sourceHomepagePdf = medicalRecordDataManageService.getHomepagePdfByOnlyId(onlyId);
			// 如果存在添加维护信息
			if(sourceHomepagePdf != null) {
				homepagePdf.setUpdateTime(new Date());
				homepagePdf.setId(sourceHomepagePdf.getId());
				homepagePdf.setCreateTime(sourceHomepagePdf.getCreateTime());
			}
			
			// 保存或更新首页pdf信息
			medicalRecordDataManageService.saveOrUpdateHomepagePdf(homepagePdf);
			
			stamper.setFormFlattening(true);// 如果为false那么生成的PDF文件还能编辑，一定要设为true
		
		}  finally {
		if (stamper != null) {
		stamper.close();
		}
		if (reader != null) {
			try {
				reader.close();
			} catch (Exception e2){
			
			}
		}
		if (bos != null) {
			try {
				bos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
		
	}
	
	
	/**
	 * 处理转科数据
	 * @param jsonMap
	 */
	private void handleTransferDeptInfo(Map<String, Object> jsonMap,ShandongHomepageExcelDTO homepageData) {
		Map<String, Object> transferDeptInfo = MapUtils.getMap(jsonMap, "transferDeptInfo");
		if (MapUtils.isEmpty(transferDeptInfo)) {
			return;
		}
	
		
		List<String> turnList = new ArrayList<>();
		List<Map<String,Object>> transferDeptRecords = (List<Map<String, Object>>) MapUtils.getObject(transferDeptInfo, "transferDeptRecords");
		
		if(org.apache.commons.collections4.CollectionUtils.isNotEmpty(transferDeptRecords)) {
			for (Map<String, Object> map : transferDeptRecords) {
				turnList.add(MapUtils.getString(map, "inDeptName"));
			}
		}
		if(CollectionUtils.isNotEmpty(turnList)) {
			// 用username字段映射转科信息
			homepageData.setUSERNAME(StringUtils.join(turnList.toArray(),","));
		}
		
		
	}


	/**
	 * 处理费用信息
	 * 
	 * @param jsonMap
	 * @param homepageData
	 */
	private void hadleCostInfo(Map<String, Object> jsonMap, ShandongHomepageExcelDTO homepageData) {
		Map<String, Object> costInfoMap = MapUtils.getMap(jsonMap, "costInfo");
		if (MapUtils.isEmpty(costInfoMap)) {
			return;
		}
		// 住院总费用
		String ZFY = ObjectUtils.getStringValue(costInfoMap.get("totalCost"));
		homepageData.setZFY(ZFY);
		// 住院总费用其中自付金额
		String ZFJE = ObjectUtils.getStringValue(costInfoMap.get("selfCost"));
		homepageData.setZFJE(ZFJE);

		List<Map<String, Object>> costRecords = (List<Map<String, Object>>) MapUtils.getObject(costInfoMap,
				"costRecords");
		if (CollectionUtils.isNotEmpty(costRecords)) {
			for (Map<String, Object> costRecord : costRecords) {

				String medicalCostTypeCode = MapUtils.getString(costRecord, "medicalCostTypeCode");
				String money = MapUtils.getString(costRecord, "costMoney");
				// 1.一般医疗服务费
				if ("C01001".equals(medicalCostTypeCode)) {
					homepageData.setYLFUF(money);
					// 2.一般治疗操作费
				} else if ("C01002".equals(medicalCostTypeCode)) {
					homepageData.setZLCZF(money);
					// 3.护理费
				} else if ("C01003".equals(medicalCostTypeCode)) {
					homepageData.setHLF(money);
					// 4.综合医疗服务类其他费用
				} else if ("C01999".equals(medicalCostTypeCode)) {
					homepageData.setQTFY(money);
					// 5.病理诊断费
				} else if ("C02001".equals(medicalCostTypeCode)) {
					homepageData.setBLZDF(money);
					// 6.实验室诊断费
				} else if ("C02002".equals(medicalCostTypeCode)) {
					homepageData.setSYSZDF(money);
					// 7.影像学诊断费
				} else if ("C02003".equals(medicalCostTypeCode)) {
					homepageData.setYXXZDF(money);
					// 8.临床诊断项目费
				} else if ("C02004".equals(medicalCostTypeCode)) {
					homepageData.setLCZDXMF(money);
					// 9.非手术治疗项目费
				} else if ("C03001".equals(medicalCostTypeCode)) {
					homepageData.setFSSZLXMF(money);
					// 其中：临床物理治疗费
				} else if ("C03002".equals(medicalCostTypeCode)) {
					homepageData.setWLZLF(money);
					// 10.手术治疗费
				} else if ("C03003".equals(medicalCostTypeCode)) {
					homepageData.setSSZLF(money);
					// 其中：麻醉费
				} else if ("C03004".equals(medicalCostTypeCode)) {
					homepageData.setMAF(money);
					// 其中：手术费
				} else if ("C03005".equals(medicalCostTypeCode)) {
					homepageData.setSSF(money);
					// 11.康复费 KFF
				} else if ("C04001".equals(medicalCostTypeCode)) {
					homepageData.setKFF(money);
					// 12.中医治疗费 ZYZLF
				} else if ("C05001".equals(medicalCostTypeCode)) {
					homepageData.setZYZLF(money);
					// 13.西药费 XYF
				} else if ("C06001".equals(medicalCostTypeCode)) {
					homepageData.setXYF(money);
					// 其中：抗菌药物费 KJYWF
				} else if ("C06002".equals(medicalCostTypeCode)) {
					homepageData.setKJYWF(money);
					// 14.中成药费 ZCYF
				} else if ("C07001".equals(medicalCostTypeCode)) {
					homepageData.setZCYF(money);
					// 15.中草药费 ZCYF1
				} else if ("C07002".equals(medicalCostTypeCode)) {
					homepageData.setZCYF1(money);
					// 16.血费 XF
				} else if ("C08001".equals(medicalCostTypeCode)) {
					homepageData.setXF(money);
					// 17.白蛋白类制品费 BDBLZPF
				} else if ("C08002".equals(medicalCostTypeCode)) {
					homepageData.setBDBLZPF(money);
					// 18.球蛋白类制品费 QDBLZPF
				} else if ("C08003".equals(medicalCostTypeCode)) {
					homepageData.setQDBLZPF(money);
					// 19.凝血因子类制品费 NXYZLZPF
				} else if ("C08004".equals(medicalCostTypeCode)) {
					homepageData.setNXYZLZPF(money);
					// 20.细胞因子类制品费
				} else if ("C08005".equals(medicalCostTypeCode)) {
					homepageData.setXBYZLZPF(money);
					// 21.检查用一次性医用材料费 HCYYCLF
				} else if ("C09001".equals(medicalCostTypeCode)) {
					homepageData.setHCYYCLF(money);
					// 22.治疗用一次性医用材料费 YYCLF
				} else if ("C09002".equals(medicalCostTypeCode)) {
					homepageData.setYYCLF(money);
					// 23.手术用一次性医用材料费 YCXYYCLF
				} else if ("C09003".equals(medicalCostTypeCode)) {
					homepageData.setYCXYYCLF(money);
					// 24.其他费： QTF
				} else if ("C99999".equals(medicalCostTypeCode)) {
					homepageData.setQTF(money);
				}
			}
		}

	}

	/**
	 * 处理手术相关数据信息
	 * 
	 * @param jsonMap
	 * @param homepageData
	 */
	private void hadleOperationInfo(Map<String, Object> jsonMap, ShandongHomepageExcelDTO homepageData) {
		Map<String, Object> operationInfoMap = MapUtils.getMap(jsonMap, "operateInfo");
		if (MapUtils.isEmpty(operationInfoMap)) {
			return;
		}
		// 获取手术信息集合
		List<Map<String, Object>> operateRecords = (List<Map<String, Object>>) MapUtils.getObject(operationInfoMap,
				"operateRecords");
		if (CollectionUtils.isEmpty(operateRecords)) {
			return;
		}

		int opsIndex = 1;
		for (Map<String, Object> operateRecord : operateRecords) {

			ReflectHelper reflectHelper = new ReflectHelper(homepageData);// 创建工具类对象
			// 手术操作编码
			reflectHelper.setMethodValue("SSJCZBM" + opsIndex, MapUtils.getString(operateRecord, "operateCode"));
			// 手术操作日期
			String operateTimeStr = MapUtils.getString(operateRecord, "operateStartDate");
			if(StringUtils.isNotBlank(operateTimeStr)) {
				try {
					// 出院日期
					Date outHospitalTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", operateTimeStr);
					// 出院日期
					reflectHelper.setMethodValue("SSJCZRQ" + opsIndex, DateUtil.dateFormat("yyyy-MM-dd", outHospitalTime));
			
				} catch (Exception e) {
					e.printStackTrace();
					logger.error("出院时间字符串转时间失败,异常信息:{}", e.getMessage());
				}
			}
		
			// 手术操作名称
			reflectHelper.setMethodValue("SSJCZMC" + opsIndex, MapUtils.getString(operateRecord, "operateName"));
			// 手术类型
			reflectHelper.setMethodValue("SSLX" + opsIndex, MapUtils.getString(operateRecord, "patientSourceName"));
			// 手术操作级别
			reflectHelper.setMethodValue("SSJB" + opsIndex, MapUtils.getString(operateRecord, "opsLevelName"));
			// 切口等级
			String incisionLevelCode = MapUtils.getString(operateRecord, "incisionLevelCode");
			if (StringUtils.isNotEmpty(incisionLevelCode)) {
				reflectHelper.setMethodValue("QKDJ" + opsIndex, convertIncisionType(incisionLevelCode));
			}

			// 手术操作切口愈合类别
			String cicatrizeTypeName = MapUtils.getString(operateRecord, "cicatrizeTypeName");
			if (StringUtils.isNotBlank(cicatrizeTypeName)) {
				
				reflectHelper.setMethodValue("QKYHLB" + opsIndex, cicatrizeTypeName);
			}

			// 麻醉方式
			String anaesthesiaTypeName = MapUtils.getString(operateRecord, "anaesthesiaTypeName");
			if (StringUtils.isNotBlank(anaesthesiaTypeName)) {
				reflectHelper.setMethodValue("MZFS" + opsIndex, anaesthesiaTypeName);
			}

			// 麻醉分级
			reflectHelper.setMethodValue("MZFJ" + opsIndex, MapUtils.getString(operateRecord, "anaesthesiaLevelCode"));
			List<Map<String, Object>> operateWorkers = (List<Map<String, Object>>) MapUtils.getObject(operateRecord,
					"operateWorkers");

		

			// 手术医师
			if (CollectionUtils.isNotEmpty(operateWorkers)) {

				for (Map<String, Object> operateWorker : operateWorkers) {
					String professionTitleCode = MapUtils.getString(operateWorker, "professionTitleCode");
					String medicalWorkerName = MapUtils.getString(operateWorker, "medicalWorkerName");
				
					
					// 手术操作术者
					if ("A5001".equals(professionTitleCode)) {
						reflectHelper.setMethodValue("SZ" + opsIndex, medicalWorkerName);
						

						// 手术操作Ⅰ助
					} else if ("A5003".equals(professionTitleCode)) {
						reflectHelper.setMethodValue("YZ" + opsIndex, medicalWorkerName);
						
						// 手术操作Ⅱ助
					} else if ("A5004".equals(professionTitleCode)) {
						reflectHelper.setMethodValue("EZ" + opsIndex, medicalWorkerName);
						
						// 麻醉医师
					} else if ("A5002".equals(professionTitleCode)) {
						// 麻醉医师姓名
						reflectHelper.setMethodValue("MZYS" + opsIndex, medicalWorkerName);
						
						
					}
				}

			}

			opsIndex++;
		}
	}

	/**
	 * 处理护理天数
	 * 
	 * @param jsonMap
	 * @param homepageData
	 */
	private void handleNurseInfo(Map<String, Object> jsonMap, ShandongHomepageExcelDTO homepageData) {
		Map<String, Object> nurseInfoMap = MapUtils.getMap(jsonMap, "nurseInfo");
		if (MapUtils.isNotEmpty(nurseInfoMap)) {
			// 特级护理天数
			homepageData.setTJHL_T(MapUtils.getString(nurseInfoMap, "specialNurseDayNumber"));
			// 一级护理天数
			homepageData.setYJHL_T(MapUtils.getString(nurseInfoMap, "firstLevelNurseDayNumber"));
			// 二级护理天数
			homepageData.setEJHL_T(MapUtils.getString(nurseInfoMap, "secondLevelNurseDayNumber"));
			// 三级护理天数
			homepageData.setSJHL_T(MapUtils.getString(nurseInfoMap, "threeLevelNurseDayNumber"));
		}
	}

	public List<String> getGuidList() {
		return guidList;
	}

	public void setGuidList(List<String> guidList) {
		this.guidList = guidList;
	}

	public MedicalRecordDataManageService getMedicalRecordDataManageService() {
		return medicalRecordDataManageService;
	}

	public void setMedicalRecordDataManageService(MedicalRecordDataManageService medicalRecordDataManageService) {
		this.medicalRecordDataManageService = medicalRecordDataManageService;
	}

	/**
	 * 设置病案初始化数据
	 */
	public void initHomepageData(ShandongHomepageExcelDTO shandongHomepageExcelDTO) {
		// 组织机构代码
		shandongHomepageExcelDTO.setZZJGDM(HomepageConstatnt.ORGANIZATION_ID);
		// 组织机构名称
		shandongHomepageExcelDTO.setJGMC(HomepageConstatnt.ORGANIZATION);
		// 对应的系统登录用户名
		shandongHomepageExcelDTO.setUSERNAME(HomepageConstatnt.USER_NAME);
	}

	/**
	 * 处理病案基本信息数据
	 * 
	 * @param jsonMap
	 * @param shandongHomepageExcelDTO
	 */
	public String handleHomepageBaiscData(Map<String, Object> jsonMap,
			ShandongHomepageExcelDTO shandongHomepageExcelDTO) {
		// 基本信息
		Map<String, Object> basicInfoMap = MapUtils.getMap(jsonMap, "basicInfo");
		if (MapUtils.isEmpty(basicInfoMap)) {
			return null;
		}
		String onlyId = MapUtils.getString(basicInfoMap, "onlyId");
		
		// 医疗付款方式
		String medicalPayTypeName = MapUtils.getString(basicInfoMap, "medicalPayTypeName");
		if (StringUtils.isNotBlank(medicalPayTypeName)) {
			shandongHomepageExcelDTO.setYLFKFS(medicalPayTypeName);
		}

		// 健康卡号
		shandongHomepageExcelDTO.setJKKH(MapUtils.getString(basicInfoMap, "medicalHealthNumber"));
		// 住院次数
		shandongHomepageExcelDTO.setZYCS(MapUtils.getString(basicInfoMap, "visitNumber"));
		// 病案号
		shandongHomepageExcelDTO.setBAH(MapUtils.getString(basicInfoMap, "mrId"));
		// 姓名
		shandongHomepageExcelDTO.setXM(MapUtils.getString(basicInfoMap, "patientName"));
		// 性别
		shandongHomepageExcelDTO.setXB(MapUtils.getString(basicInfoMap, "sexName"));
		// 出生日期
		String birthdayStr = MapUtils.getString(basicInfoMap, "birthday");
		if (StringUtils.isNotBlank(birthdayStr) && !birthdayStr.equals("null")) {
			try {
				Date birthday = DateUtil.dateParse("yyyy-MM-dd", birthdayStr);
				shandongHomepageExcelDTO.setCSRQ(DateUtil.dateFormat("yyyy年MM月dd日", birthday));
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("出生日期转换异常，异常信息:"+e.getMessage());
			}
			
		}
		// 年龄
		String ageStr = MapUtils.getString(basicInfoMap, "yearOfAge");
		shandongHomepageExcelDTO.setNL(ageStr);
		
		shandongHomepageExcelDTO.setBZYZSNL(MapUtils.getString(basicInfoMap, "yearOfMonth"));
		
		// 国籍
		String nationalityName = MapUtils.getString(basicInfoMap, "nationalityName");
		if (StringUtils.isNotBlank(nationalityName)) {
			shandongHomepageExcelDTO.setGJ(nationalityName);
		}

		Map<String, Object> birthRegionalismMap = MapUtils.getMap(basicInfoMap, "birthRegionalism");
		if (MapUtils.isNotEmpty(birthRegionalismMap)) {
			// 出生地—详细地址
			shandongHomepageExcelDTO.setCSD_DZ(MapUtils.getString(birthRegionalismMap, "fullAddress"));
		}

		// 籍贯—省
		Map<String, Object> nativePlaceRegionalismMap = MapUtils.getMap(basicInfoMap, "nativePlaceRegionalism");
		if (MapUtils.isNotEmpty(nativePlaceRegionalismMap)) {
		
			// 籍贯—市
			shandongHomepageExcelDTO.setJG_SI(MapUtils.getString(nativePlaceRegionalismMap, "fullAddress"));

		}
		// 民族
		shandongHomepageExcelDTO.setMZ(MapUtils.getString(basicInfoMap, "nationName"));
		

		// 身份证件类别
		shandongHomepageExcelDTO.setSFZJLB(MapUtils.getString(basicInfoMap, "documentTypeName"));
		// 身份证号
		shandongHomepageExcelDTO.setSFZH(MapUtils.getString(basicInfoMap, "idNumber"));
		// 职业
		shandongHomepageExcelDTO.setZY(MapUtils.getString(basicInfoMap, "professionName"));
		// 婚姻
		shandongHomepageExcelDTO.setHY(MapUtils.getString(basicInfoMap, "marriageName"));

		// 现住址
		Map<String, Object> permanentAddressRegionalismMap = MapUtils.getMap(basicInfoMap,
				"permanentAddressRegionalism");
		if (MapUtils.isNotEmpty(permanentAddressRegionalismMap)) {

			//现住址
			shandongHomepageExcelDTO.setXZZ_DZ(MapUtils.getString(permanentAddressRegionalismMap, "fullAddress"));

		}
		// 电话
		shandongHomepageExcelDTO.setDH(MapUtils.getString(basicInfoMap, "permanentAddressPhone"));
		// 邮编
		shandongHomepageExcelDTO.setYB1(MapUtils.getString(basicInfoMap, "permanentAddressPostCode"));

		// 户口地址
		Map<String, Object> registeredAddressRegionalismMap = MapUtils.getMap(basicInfoMap,
				"registeredAddressRegionalism");
		if (MapUtils.isNotEmpty(registeredAddressRegionalismMap)) {
			shandongHomepageExcelDTO.setHKDZ_DZ(MapUtils.getString(registeredAddressRegionalismMap, "fullAddress"));
		}

		// 户口邮编
		shandongHomepageExcelDTO.setYB2(MapUtils.getString(basicInfoMap, "registeredAddressPostCode"));

		// 工作单位名称
		shandongHomepageExcelDTO.setGZDWJDZMC(MapUtils.getString(basicInfoMap, "workUnitName"));

		// 工作单位
		Map<String, Object> workUnitRegionalismMap = MapUtils.getMap(basicInfoMap, "workUnitRegionalism");
		if (MapUtils.isNotEmpty(workUnitRegionalismMap)) {
			// 工作单位及地址—省
			shandongHomepageExcelDTO.setGZDWJDZ_SG(MapUtils.getString(workUnitRegionalismMap, "provinceCode"));

			// 工作单位及地址—市
			shandongHomepageExcelDTO.setGZDWJDZ_SI(MapUtils.getString(workUnitRegionalismMap, "cityCode"));

			// 工作单位及地址—区县
			shandongHomepageExcelDTO.setGZDWJDZ_QX(MapUtils.getString(workUnitRegionalismMap, "countyCode"));

			// 工作单位及地址—详细地址
			shandongHomepageExcelDTO.setGZDWJDZ_DZ(MapUtils.getString(workUnitRegionalismMap, "fullAddress"));

		}
		// 工作单位电话
		shandongHomepageExcelDTO.setDWDH(MapUtils.getString(basicInfoMap, "workUnitPhone"));
		// 工作单位邮政编码
		String workUnitPostCode = MapUtils.getString(basicInfoMap, "workUnitPostCode");
		shandongHomepageExcelDTO.setYB3(workUnitPostCode == null ? "-" : workUnitPostCode);
		// 联系人姓名
		shandongHomepageExcelDTO.setLXRXM(MapUtils.getString(basicInfoMap, "linkManName"));
		// 联系人关系
		String linkManRelativeRelationCode = MapUtils.getString(basicInfoMap, "linkManRelativeRelationName");
		if (StringUtils.isNotBlank(linkManRelativeRelationCode)) {
			// 联系人关系8需要映射为9
			shandongHomepageExcelDTO.setGX(linkManRelativeRelationCode);
		}

		Map<String, Object> linkManAddressRegionalismMap = MapUtils.getMap(basicInfoMap, "linkManAddressRegionalism");
		if (MapUtils.isNotEmpty(linkManAddressRegionalismMap)) {
			// 联系人地址—详细地址
			shandongHomepageExcelDTO.setDZ_DZ(MapUtils.getString(linkManAddressRegionalismMap, "fullAddress"));
		}

		// 联系人电话
		shandongHomepageExcelDTO.setDH2(MapUtils.getString(basicInfoMap, "linkManPhone"));

		// 入院途径
		String inHospitalTypeCode = MapUtils.getString(basicInfoMap, "inHospitalTypeCode");
		if (StringUtils.isNotBlank(inHospitalTypeCode)) {
			
			shandongHomepageExcelDTO.setRYTJ(inHospitalTypeCode);
		}

		// 转诊医疗机构名称
		shandongHomepageExcelDTO.setZZYLJGMC(MapUtils.getString(basicInfoMap, "shiftToUnitName"));
		String inTime = MapUtils.getString(basicInfoMap, "inHospitalDateTime");

		if (StringUtils.isNotBlank(inTime) && !"null".equals(inTime)) {
			try {
				Date inHospitalTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", inTime);
				// 入院时间
				shandongHomepageExcelDTO.setRYSJ(DateUtil.dateFormat("yyyy年MM月dd日HH时", inHospitalTime));
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("入院时间字符串转时间失败,异常信息:{}", e.getMessage());
			}
		}

		// 入院科室
		String inDeptName = MapUtils.getString(basicInfoMap, "inDeptName");
		if (StringUtils.isNotEmpty(inDeptName)) {
			shandongHomepageExcelDTO.setRYKB(inDeptName);
		}

		// 入院病房
		shandongHomepageExcelDTO.setRYBF(MapUtils.getString(basicInfoMap, "inHospitalHouseName"));

		// 出院日期
		String outTimeStr = MapUtils.getString(basicInfoMap, "outHospitalDateTime");

		if (StringUtils.isNotBlank(outTimeStr) && !"null".equals(outTimeStr)) {

			try {
				// 出院日期
				Date outHospitalTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", outTimeStr);
				// 出院日期
				shandongHomepageExcelDTO.setCYSJ(DateUtil.dateFormat("yyyy年MM月dd日HH时", outHospitalTime));
		
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("出院时间字符串转时间失败,异常信息:{}", e.getMessage());
			}
		}

		// 出院科别
		String outDeptName = MapUtils.getString(basicInfoMap, "outDeptName");
		if (StringUtils.isNotEmpty(outDeptName)) {
			shandongHomepageExcelDTO.setCYKB(outDeptName);
		}

		// 出院病房
		shandongHomepageExcelDTO.setCYBF(MapUtils.getString(basicInfoMap, "outHospitalHouseName"));

		// 实际住院天数
		shandongHomepageExcelDTO.setSJZYTS(MapUtils.getString(basicInfoMap, "inHospitalDayNumber"));

		// 入院诊断确诊时间
		String diagConfirmedDateTimeStr = MapUtils.getString(basicInfoMap, "diagConfirmedDateTime");
		if (StringUtils.isNotBlank(diagConfirmedDateTimeStr) && !"null".equals(diagConfirmedDateTimeStr)) {

			try {
				// 出院日期
				Date diagConfirmedDateTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", diagConfirmedDateTimeStr);
				// 出院日期
				shandongHomepageExcelDTO.setRYHQZRQ(DateUtil.dateFormat("yyyy-MM-dd", diagConfirmedDateTime));

			} catch (Exception e) {
				e.printStackTrace();
				logger.error("入院后确诊时间字符串转时间失败,异常信息:{}", e.getMessage());
			}
		}

		// 有无药物过敏
		shandongHomepageExcelDTO.setYWGM(MapUtils.getString(basicInfoMap, "whetherDrugAllergyCode"));
		// 过敏药物
		shandongHomepageExcelDTO.setGMYW(MapUtils.getString(basicInfoMap, "drugAllergyDesc"));
		// 死亡患者尸检
		String SWHZSJ = MapUtils.getString(basicInfoMap, "autopsyCode");
		if (SWHZSJ != null && SWHZSJ.startsWith("-")) {
			SWHZSJ = null;
		}
		shandongHomepageExcelDTO.setSWHZSJ(SWHZSJ);

		// 离院方式
		shandongHomepageExcelDTO.setLYFS(MapUtils.getString(basicInfoMap, "outHospitalTypeCode"));
		// 医嘱转院，拟接收医疗机构名称
		shandongHomepageExcelDTO.setYZZY_YLJG(MapUtils.getString(basicInfoMap, "receiveUnitName"));
		return onlyId;
	}

	/**
	 * 处理诊断信息
	 * 
	 * @param jsonMap      json数据
	 * @param homepageData 首页数据信息
	 */
	@SuppressWarnings("unchecked")
	private void handleDiagInfo(Map<String, Object> jsonMap, ShandongHomepageExcelDTO homepageData) {
		// 从json中获取疾病信息
		Map<String, Object> diseaseDiagInfoMap = MapUtils.getMap(jsonMap, "diseaseDiagInfo");
		if (MapUtils.isEmpty(diseaseDiagInfoMap)) {
			return;
		}
		// 获取门诊信息
		Map<String, Object> outpatientDiagRecordMap = MapUtils.getMap(diseaseDiagInfoMap, "outpatientDiagRecord");
		if (MapUtils.isNotEmpty(outpatientDiagRecordMap)) {
			String outpatientDiagName = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagName");
			String outpatientDiagCode = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagCode");
			String diseaseDiagOriginalCode = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalCode");
			String diseaseDiagOriginalDesc = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalDesc");
			// 门（急）诊诊断名称
			homepageData
					.setMZZD(StringUtils.isEmpty(outpatientDiagName) ? diseaseDiagOriginalDesc : outpatientDiagName);
			// 门（急）诊诊断编码
			homepageData
					.setJBBM(StringUtils.isEmpty(outpatientDiagCode) ? diseaseDiagOriginalCode : outpatientDiagCode);

		}

		// 主要诊断信息
		Map<String, Object> mainDiagRecordMap = MapUtils.getMap(diseaseDiagInfoMap, "mainDiagRecord");
		if (MapUtils.isNotEmpty(mainDiagRecordMap)) {
			String mainDiagName = ObjectUtils.getStringValue(mainDiagRecordMap.get("diseaseDiagName"));
			if (StringUtils.isEmpty(mainDiagName)) {
				mainDiagName = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalDesc");
			}
			String mainDiagCode = ObjectUtils.getStringValue(mainDiagRecordMap.get("diseaseDiagCode"));
			if (StringUtils.isEmpty(mainDiagCode)) {
				mainDiagCode = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalCode");
			}

			/*
			 * if (mainDiagCode != null && (mainDiagCode.endsWith("?") ||
			 * mainDiagCode.endsWith("†"))) { mainDiagCode = mainDiagCode.replace("?",
			 * "+").replace("†", "+"); List<Map<String, Object>> extraMainDiagMapList =
			 * (List<Map<String, Object>>) MapUtils .getObject(mainDiagRecordMap,
			 * "diseaseExtraDiagRecords"); for (Map<String, Object> extraMainDiagMap :
			 * extraMainDiagMapList) { String diseaseExtraDiagCode =
			 * MapUtils.getString(extraMainDiagMap, "diseaseExtraDiagCode"); if
			 * (StringUtils.isNotEmpty(diseaseExtraDiagCode) &&
			 * diseaseExtraDiagCode.contains("*")) { mainDiagCode = mainDiagCode +
			 * diseaseExtraDiagCode; } } }
			 */

			// 出院主要诊断名称
			homepageData.setZYZD(mainDiagName);
			// 出院主要诊断编码
			homepageData.setJBDM(mainDiagCode);

			// 入院病情
			String rybq = MapUtils.getString(mainDiagRecordMap, "inHospitalDiseaseStateCode");
			// 出院主要诊断入院病情
			homepageData.setRYBQ(StringUtils.isEmpty(rybq) ? "4" : rybq);
		}

		// 其他诊断
		List<Map<String, Object>> otherDiseaseDiagRecords = (List<Map<String, Object>>) MapUtils
				.getObject(diseaseDiagInfoMap, "diseaseDiagRecords");

		if (CollectionUtils.isNotEmpty(otherDiseaseDiagRecords)) {
			int otherDiagIndex = 1;
			for (Map<String, Object> otherDiseaseDiagRecord : otherDiseaseDiagRecords) {
				String otherDiagName = MapUtils.getString(otherDiseaseDiagRecord, "diseaseDiagName");
				if (StringUtils.isEmpty(otherDiagName)) {
					otherDiagName = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalDesc");
				}
				String otherDiagCode = MapUtils.getString(otherDiseaseDiagRecord, "diseaseDiagCode");
				if (StringUtils.isEmpty(otherDiagCode)) {
					otherDiagCode = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalCode");
				}
//				if (StringUtils.isNotBlank(otherDiagCode)
//						&& (otherDiagCode.endsWith("?") || otherDiagCode.endsWith("†"))) {
//					otherDiagCode = otherDiagCode.replace("?", "+").replace("†", "+");
//					List<Map<String, Object>> otherExtraDiagRecords = (List<Map<String, Object>>) MapUtils
//							.getObject(otherDiseaseDiagRecord, "diseaseExtraDiagRecords");
//					for (Map<String, Object> otherExtraDiagRecord : otherExtraDiagRecords) {
//						String otherDiseaseExtraDiagCode = MapUtils.getString(otherExtraDiagRecord,
//								"diseaseExtraDiagCode");
//
//						if (StringUtils.isNotEmpty(otherDiseaseExtraDiagCode)
//								&& otherDiseaseExtraDiagCode.contains("*")) {
//							otherDiagCode = otherDiagCode + otherDiseaseExtraDiagCode;
//						}
//					}
//
//				}

				ReflectHelper reflectHelper = new ReflectHelper(homepageData);// 创建工具类对象
				// 出院其他诊断名称
				reflectHelper.setMethodValue("QTZD" + otherDiagIndex, otherDiagName);
				// 出院其他诊断编码
				reflectHelper.setMethodValue("JBDM" + otherDiagIndex, otherDiagCode);
				// 出院其他诊断入院病情
				String rybq = MapUtils.getString(otherDiseaseDiagRecord, "inHospitalDiseaseStateCode");
				reflectHelper.setMethodValue("RYBQ" + otherDiagIndex, StringUtils.isEmpty(rybq) ? "4" : rybq);
			
				otherDiagIndex++;

			}
		}

		// 中毒的外部原因
		List<Map<String, Object>> damageAndVenenationDiagRecords = (List<Map<String, Object>>) MapUtils
				.getObject(diseaseDiagInfoMap, "damageAndVenenationDiagRecords");

		if (CollectionUtils.isNotEmpty(damageAndVenenationDiagRecords)) {
			Map<String, Object> damageAndVenenationDiagRecord = damageAndVenenationDiagRecords.get(0);
			String damageAndVenenationDiagName = MapUtils.getString(damageAndVenenationDiagRecord, "diseaseDiagName");

			String damageAndVenenationDiagCode = MapUtils.getString(damageAndVenenationDiagRecord, "diseaseDiagCode");

			// 损伤、中毒外部原因名称
			homepageData.setWBYY(damageAndVenenationDiagName);
			// 损伤、中毒外部原因编码
			homepageData.setWBYYCODE(damageAndVenenationDiagCode);
		}

		// 病理诊断
		List<Map<String, Object>> pathologyDiagRecords = (List<Map<String, Object>>) MapUtils
				.getObject(diseaseDiagInfoMap, "pathologyDiagRecords");
		if (CollectionUtils.isNotEmpty(pathologyDiagRecords)) {
			Map<String, Object> pathologyDiagRecord = pathologyDiagRecords.get(0);
			String pathologyDiagName = ObjectUtils.getStringValue(pathologyDiagRecord.get("diseaseDiagName"));
			String pathologyDiagCode = ObjectUtils.getStringValue(pathologyDiagRecord.get("diseaseDiagCode"));
			// 病理诊断名称
			homepageData.setBLZD(pathologyDiagName);
			// 病理诊断编码
			homepageData.setJBMM(pathologyDiagCode);
			// 病理号
			homepageData.setBLH(MapUtils.getString(pathologyDiagRecord, "pathologyNumber"));

		}

	}

	/**
	 * 处理病案治疗信息数据
	 * 
	 * @param jsonMap
	 * @param shandongHomepageExcelDTO
	 */
	public void handleCureInfoData(Map<String, Object> jsonMap, ShandongHomepageExcelDTO shandongHomepageExcelDTO) {
		Map<String, Object> cureInfoMap = MapUtils.getMap(jsonMap, "cureInfo");
		if (MapUtils.isEmpty(cureInfoMap)) {
			return;
		}

		// 新生儿出生体重（克） XSECSTZ
		shandongHomepageExcelDTO.setXSECSTZ(MapUtils.getString(cureInfoMap, "babyBirthWeight"));

		// 新生儿入院体重（克） XSERYTZ
		shandongHomepageExcelDTO.setXSERYTZ(MapUtils.getString(cureInfoMap, "babyInHospitalWeight"));

		// 最高诊断依据
		shandongHomepageExcelDTO.setZGZDYJ(MapUtils.getString(cureInfoMap, "malignantTumorHighestDiagBasisName"));
		// ABO血型
		shandongHomepageExcelDTO.setXX(MapUtils.getString(cureInfoMap, "bloodTypeCode"));
		// RH血型
		shandongHomepageExcelDTO.setRH(MapUtils.getString(cureInfoMap, "rhBloodTypeCode"));
		// HBsAg
		shandongHomepageExcelDTO.setHBSAG(MapUtils.getString(cureInfoMap, "hbsAgeResultCode"));
		// HCV-Ab
		shandongHomepageExcelDTO.setHCVAb(MapUtils.getString(cureInfoMap, "hcvAbResultCode"));
		// HIV-Ab
		shandongHomepageExcelDTO.setHIVAb(MapUtils.getString(cureInfoMap, "hivAbResultCode"));
		// 日间手术
		String rjss = MapUtils.getString(cureInfoMap, "isDaySurgeryCode");
		if (StringUtils.isNotBlank(rjss)) {
			shandongHomepageExcelDTO.setSFWRJSS("2".equals(rjss) ? "0" : "1");
		}

		// 有创呼吸机使用时间
		Integer ventilatorServiceHour = 0;
		String invasiveVentilatorDay = MapUtils.getString(cureInfoMap, "invasiveVentilatorDay");
		if (StringUtils.isNotEmpty(invasiveVentilatorDay)) {
			try {
				ventilatorServiceHour += (Integer.parseInt(invasiveVentilatorDay)) * 24;
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("有创呼吸机天转小时出现错误,异常信息:{}", e.getMessage());
			}

		}
		String invasiveVentilatorHour = MapUtils.getString(cureInfoMap, "invasiveVentilatorHour");
		if (StringUtils.isNotEmpty(invasiveVentilatorHour)) {
			try {
				ventilatorServiceHour += Integer.parseInt(invasiveVentilatorHour);
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("有创呼吸机字符串小时转数字出现错误,异常信息:{}", e.getMessage());
			}

		}

		String invasiveVentilatorMinute = MapUtils.getString(cureInfoMap, "invasiveVentilatorMinute");
		if (StringUtils.isNotEmpty(invasiveVentilatorMinute)) {
			try {
				Integer minutes = Integer.parseInt(invasiveVentilatorMinute);
				ventilatorServiceHour += minutes % 60 != 0 ? minutes / 60 + 1 : minutes / 60;
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("有创呼吸机字符串分钟转数字出现错误,异常信息:{}", e.getMessage());
			}

		}
		shandongHomepageExcelDTO.setYCHXJSYSJ(ventilatorServiceHour + "");

		// 重症监护室名称1 ZZJHSMC1
		shandongHomepageExcelDTO.setZZJHSMC1(MapUtils.getString(cureInfoMap, "intensiveCareUnit1Code"));
		// 进入时间1 JRSJ1
		shandongHomepageExcelDTO.setJRSJ1(MapUtils.getString(cureInfoMap, "intensiveCareUnit1StartTime"));
		// 退出时间1 TCSJ1
		shandongHomepageExcelDTO.setTCSJ1(MapUtils.getString(cureInfoMap, "intensiveCareUnit1EndTime"));

		// 重症监护室名称2 ZZJHSMC2
		shandongHomepageExcelDTO.setZZJHSMC2(MapUtils.getString(cureInfoMap, "intensiveCareUnit2Code"));
		// 进入时间2 JRSJ2
		shandongHomepageExcelDTO.setJRSJ2(MapUtils.getString(cureInfoMap, "intensiveCareUnit2StartTime"));
		// 退出时间2 TCSJ2
		shandongHomepageExcelDTO.setTCSJ2(MapUtils.getString(cureInfoMap, "intensiveCareUnit2EndTime"));

		// 重症监护室名称3 ZZJHSMC3
		shandongHomepageExcelDTO.setZZJHSMC3(MapUtils.getString(cureInfoMap, "intensiveCareUnit3Code"));
		// 进入时间3 JRSJ3
		shandongHomepageExcelDTO.setJRSJ3(MapUtils.getString(cureInfoMap, "intensiveCareUnit3StartTime"));
		// 退出时间3 TCSJ3
		shandongHomepageExcelDTO.setTCSJ3(MapUtils.getString(cureInfoMap, "intensiveCareUnit3EndTime"));

		List<Map<String, Object>> medicalWorks = (List<Map<String, Object>>) MapUtils.getObject(cureInfoMap,
				"cureWorkers");

		if (CollectionUtils.isNotEmpty(medicalWorks)) {

			for (Map<String, Object> medicalWork : medicalWorks) {

				String professionTitleCode = MapUtils.getString(medicalWork, "professionTitleCode");
				String medicalWorkerName = MapUtils.getString(medicalWork, "medicalWorkerName");
				String medicalWorkerCode = MapUtils.getString(medicalWork, "medicalWorkerCode");
		
				// 科主任
				if ("A1001".equals(professionTitleCode)) {
					// 科主任姓名
					shandongHomepageExcelDTO.setKZR(medicalWorkerName);
			
					// 医疗组长
				} else if ("A1003".equals(professionTitleCode)) {
					// 医疗组长姓名
					shandongHomepageExcelDTO.setYLZZ(medicalWorkerName);
				
					// 主任医师
				} else if ("A2001".equals(professionTitleCode)) {
					// 主任医师姓名
					shandongHomepageExcelDTO.setZRYS(medicalWorkerName);
				
					// 主治医师
				} else if ("A2003".equals(professionTitleCode)) {
					// 主治医师姓名
					shandongHomepageExcelDTO.setZZYS(medicalWorkerName);
				
					// 住院医师
				} else if ("A2005".equals(professionTitleCode)) {
					// 住院医师姓名
					shandongHomepageExcelDTO.setZYYS(medicalWorkerName);
				
					// 责任护士
				} else if ("A3001".equals(professionTitleCode)) {
					// 责任护士姓名
					shandongHomepageExcelDTO.setZRHS(medicalWorkerName);
				
					// 进修医师
				} else if ("A2006".equals(professionTitleCode)) {
					// 进修医师姓名
					shandongHomepageExcelDTO.setJXYS(medicalWorkerName);
				
				}
				// 实习医师
				else if ("A2008".equals(professionTitleCode)) {
					// 实习医师姓名
					shandongHomepageExcelDTO.setSXYS(medicalWorkerName);
					// 编码员
				} else if ("A4001".equals(professionTitleCode)) {
					// 编码员姓名
					shandongHomepageExcelDTO.setBMY(medicalWorkerName);
				
					// 质控医师
				} else if ("A2009".equals(professionTitleCode)) {
					// 质控医师姓名
					shandongHomepageExcelDTO.setZKYS(medicalWorkerName);
				
					// 质控护士
				} else if ("A3003".equals(professionTitleCode)) {
					// 质控护士姓名

					shandongHomepageExcelDTO.setZKHS(medicalWorkerName.equals("001682") ? "武美玲" : medicalWorkerName);
				
				}
			}

			// 病案质量
			shandongHomepageExcelDTO.setBAZL(MapUtils.getString(cureInfoMap, "medicalRecordQualityCode"));
			// 质控日期
			String qualityTimeStr = MapUtils.getString(cureInfoMap, "qualityControlDateTime");
			if (StringUtils.isNotBlank(qualityTimeStr)) {
				try {
					Date qualityDateTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", qualityTimeStr);
					shandongHomepageExcelDTO.setZKRQ(DateUtil.dateFormat("yyyy年MM月dd日", qualityDateTime));
				} catch (Exception e) {
					e.printStackTrace();
					logger.error("质控日期转换失败,异常信息:" + e.getMessage());
				}
			}

		}

		// 入径情况
		shandongHomepageExcelDTO.setRJQK(MapUtils.getString(cureInfoMap, "whetherEnterClinicalPathsCode"));
		// 完成情况
		shandongHomepageExcelDTO.setWCQK(MapUtils.getString(cureInfoMap, "whetherFinishClinicalPathsCode"));
		// 变异情况
		shandongHomepageExcelDTO.setBYQK(MapUtils.getString(cureInfoMap, "whetherConditionVariationCode"));
		// 是否有出院31日内再住院计划
		shandongHomepageExcelDTO.setSFZZYJH(MapUtils.getString(cureInfoMap, "rehospitalAimOf31Code"));
		// 出院31天再住院计划目的
		shandongHomepageExcelDTO.setMD(MapUtils.getString(cureInfoMap, "rehospitalAimOf31Description"));

		// 颅脑损伤患者入院前昏迷时间（天）
		String dayOfBeforeInHospitalComa = MapUtils.getString(cureInfoMap, "dayOfBeforeInHospitalComa");
		shandongHomepageExcelDTO
				.setRYQ_T(StringUtils.isEmpty(dayOfBeforeInHospitalComa) ? "0" : dayOfBeforeInHospitalComa);
		// 颅脑损伤患者入院前昏迷时间（小时）
		String hourOfBeforeInHospitalComa = MapUtils.getString(cureInfoMap, "hourOfBeforeInHospitalComa");
		shandongHomepageExcelDTO
				.setRYQ_XS(StringUtils.isEmpty(hourOfBeforeInHospitalComa) ? "0" : hourOfBeforeInHospitalComa);
		// 颅脑损伤患者入院前昏迷时间（分钟）
		String minuteOfBeforeInHospitalComa = MapUtils.getString(cureInfoMap, "minuteOfBeforeInHospitalComa");
		shandongHomepageExcelDTO
				.setRYQ_F(StringUtils.isEmpty(minuteOfBeforeInHospitalComa) ? "0" : minuteOfBeforeInHospitalComa);
		// 颅脑损伤患者入院后昏迷时间（天）
		String dayOfAfterInHospitalComa = MapUtils.getString(cureInfoMap, "dayOfAfterInHospitalComa");
		shandongHomepageExcelDTO
				.setRYH_T(StringUtils.isEmpty(dayOfAfterInHospitalComa) ? "0" : dayOfAfterInHospitalComa);
		// 颅脑损伤患者入院后昏迷时间（小时）
		String hourOfAfterInHospitalComa = MapUtils.getString(cureInfoMap, "hourOfAfterInHospitalComa");
		shandongHomepageExcelDTO
				.setRYH_XS(StringUtils.isEmpty(hourOfAfterInHospitalComa) ? "0" : hourOfAfterInHospitalComa);
		// 颅脑损伤患者入院后昏迷时间（分钟）
		String minuteOfAfterInHospitalComa = MapUtils.getString(cureInfoMap, "minuteOfAfterInHospitalComa");
		shandongHomepageExcelDTO
				.setRYH_F(StringUtils.isEmpty(minuteOfAfterInHospitalComa) ? "0" : minuteOfAfterInHospitalComa);
	}

	public Map<String, Object> getAnaesthesiaMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		// 01 全身麻醉
		map.put("1", "01");
		// 0101 吸入麻醉 （气管内插管、喉罩、面罩）
		map.put("11", "0101");
		// 0102 静脉麻醉 （全凭静脉麻醉）
		map.put("12", "0102");
		// 0103 静吸复合麻醉
		map.put("41", "0103");
		// 0104 基础麻醉 （直肠注入、肌肉注射）
		map.put("13", "0104");
		// 02 区域麻醉
		// map.put("2", "02");
		// 0201 椎管内麻醉
		map.put("2", "0201");
		// 020101 蛛网膜下腔阻滞 ||蛛网膜下腔阻滞麻醉
		map.put("21", "020101");
		// 020102 硬膜外间隙阻滞（含骶管阻滞）||硬脊膜外腔阻滞麻醉
		map.put("22", "99");
		// 3 局部麻醉
		map.put("3", "03");
		// 31 神经丛阻滞麻醉
		map.put("31", "0202");
		// 32神经节阻滞麻醉
		map.put("32", "0202");
		// 33神经阻滞麻醉
		map.put("33", "0202");
		// 34 区域阻滞麻醉
		map.put("34", "99");
		// 35局部浸润麻醉
		map.put("35", "0302");
		// 36表面麻醉
		map.put("36", "0301");
		// 4 复合麻醉
		map.put("4", "05");
		// 41 静吸复合麻醉
		// map.put("41", "0502");
		// 42 针药复合麻醉
		map.put("42", "0502");
		// 43 神经丛与硬膜外阻滞复合麻醉
		map.put("43", "99");
		// 44 全麻复合全身降温
		map.put("44", "0503");
		// 45 全麻复合控制性降压
		map.put("45", "0503");
		// 9 其他麻醉方法
		map.put("9", "99");
		// 9 其他麻醉方法

		return map;
	}

	private static Map<String, Object> getDeptMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		// map.put("2001", "03.05");
		map.put("2001", "19.10");
		map.put("2002", "03.05");
		map.put("2003", "03.04");

		map.put("2004", "03.04");
		map.put("2005", "03.06");
		map.put("2006", "03.07");
		map.put("2007", "03.03");
		map.put("2008", "03.03");
		map.put("20106", "03.03");

		map.put("2009", "16");
		map.put("2010", "03.02");
		map.put("2011", "03.01");
		map.put("2038", "03.01");
		map.put("2012", "04.01");
		map.put("2013", "04.01");
		map.put("2014", "08");
		// map.put("2015", "04.01");
		map.put("2015", "04.01.13");
		// 骨科一区病区
		map.put("2016", "04.03");
		// 骨科二区病区
		map.put("2017", "04.03");
		// 骨科一病区单元
		map.put("20045", "04.03");
		// 骨科一病区
		map.put("20059", "04.03");
		map.put("2018", "04.05");
		map.put("2019", "04.04");
		map.put("2020", "04.02");

		map.put("2021", "05.01");
		map.put("2022", "05.02");
		map.put("2023", "05.02");
		map.put("2024", "05.02");
		map.put("2025", "07");
		map.put("2026", "07");
		map.put("2027", "07.01");
		map.put("2028", "10");
		map.put("2029", "12");
		map.put("2030", "11");
		map.put("2031", "21");
		map.put("2032", "28");
		map.put("20001", "03.05");
		map.put("20201", "03.05");
		map.put("20002", "03.04");
		map.put("20003", "03.04");

		map.put("20004", "03.06");
		map.put("20005", "03.07");
		map.put("20006", "03.03");
		map.put("20007", "03.03");
		map.put("20106", "03.03");

		map.put("20008", "16");
		map.put("20009", "03.02");
		map.put("20010", "03.01");
		map.put("20110", "03.01");

		map.put("20011", "04.01");

		map.put("20012", "04.01");
		map.put("20018", "08");
		map.put("20013", "04.01");
		map.put("20059", "04.03");
		map.put("20014", "04.03");
		map.put("20015", "04.05");

		map.put("20016", "04.04");
		map.put("20017", "04.02");
		map.put("20019", "05.01");
		map.put("20058", "05.02");
		map.put("20057", "05.02");
		map.put("20071", "05.02");

		map.put("20023", "07");
		map.put("20024", "07");
		map.put("20025", "07");
		map.put("20026", "10");
		map.put("20028", "12");
		map.put("20027", "11");

		map.put("20072", "21");
		map.put("20029", "28");
		map.put("30011", "21");
		map.put("20058", "05.02");
		// 骨科二病区
		map.put("20014", "04.03");

		map.put("20057", "05.02");
		// 骨科二病区单元
		map.put("20145", "04.03");

		// 手足外科
		map.put("2043", "04.03.13");
		
		// 急诊医学科病区
				map.put("2041", "20");
				// 儿科扩展病区
				map.put("2056", "07");
				//2063  中医日间病房一病区
				map.put("2063", "50");
				// 中医日间病房二病区
				map.put("2067", "50");
				// 安宁疗护一病区
				map.put("2064", "24");
				// 安宁疗护二病区
				map.put("2065", "24");
				// 安宁疗护三病区
				map.put("2066", "24");
				// 肿瘤日间病房一病区
				map.put("2068", "19");
				// 肿瘤日间病房二病区
				map.put("2069", "19");
				// 重症医学科扩展病房
				map.put("2048", "28");
		return map;

	}

	/**
	 * 医疗付费方式字典和卫统报表字典转换
	 */
	private String convertMedicalPayType(String medicalPayTypeCode) {
		String switchCode = null;
		if ("01".equals(medicalPayTypeCode)) {
			switchCode = "1.1";
		} else if ("02".equals(medicalPayTypeCode)) {
			switchCode = "2.1";
		} else if ("03".equals(medicalPayTypeCode)) {
			switchCode = "3.1";
		} else if ("04".equals(medicalPayTypeCode)) {
			switchCode = "4";
		} else if ("05".equals(medicalPayTypeCode)) {
			switchCode = "5";
		} else if ("06".equals(medicalPayTypeCode)) {
			switchCode = "6";
		} else if ("07".equals(medicalPayTypeCode)) {
			switchCode = "7";
		} else if ("08".equals(medicalPayTypeCode)) {
			switchCode = "8";
		} else if ("99".equals(medicalPayTypeCode)) {
			switchCode = "9";
		}
		return switchCode;
	}

	/**
	 * 切口等级转换
	 * 
	 * @param incisionType
	 * @return
	 */
	private String convertIncisionType(String incisionType) {
		String switchCode = null;
		if ("0".equals(incisionType)) {
			switchCode = "1";
		} else if ("1".equals(incisionType)) {
			switchCode = "2";
		} else if ("2".equals(incisionType)) {
			switchCode = "3";
		} else if ("3".equals(incisionType)) {
			switchCode = "4";
		} else if ("9".equals(incisionType)) {
			switchCode = "1";
		}
		return switchCode;
	}

}
